#include "Lightning.h"

namespace PeanutQuest {

	Lightning::Lightning(std::string id) : cg::Entity(id) {
	}
	Lightning::~Lightning() {
	}
	void Lightning::init() {
		GLfloat ambient_light[] = {1.0f,0.0f,0.0f,1.0f};
		GLfloat diffuse_light[] = {0.9f,0.9f,0.9f,1.0f};
		GLfloat specular_light[] = {0.9f,0.9f,0.9f,1.0f};
		glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_light);
		glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light);
		glLightfv(GL_LIGHT0, GL_SPECULAR, specular_light);

		glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0f);

		//glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 45.0f); // Luz spot
		glEnable(GL_LIGHT0);

		makeLight();
		_isDebug = false;
	}

	inline
	void Lightning::makeLight() {
		float position[] = {0.0,10.0,0.0,0.0}; //Luz direcional
		float direction[] = {0.0,-1.0,0.0};
		_lightDL = glGenLists(1);
		assert(_lightDL != 0);
		glNewList(_lightDL,GL_COMPILE);
			glLightfv(GL_LIGHT0, GL_POSITION, position);
			glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, direction);
		glEndList();
	}
	void Lightning::update(unsigned long elapsed_millis) {
		
	}

	void Lightning::draw() {
		glEnable(GL_LIGHTING);
		glPushMatrix();
			glCallList(_lightDL);
		//	glTranslatef(0,9.5,0);
		//	glutSolidCube(1);
		glPopMatrix(); 
		/*
		if(_isDebug) {
			glDisable(GL_LIGHTING);
			glPushMatrix();
			glPopMatrix();
			glPushMatrix();
				glColor3f(0.9f,0.9f,0.9f);
				glTranslatef(0.4f,0.0f,0.0f);
				glRotatef(-90.0f,0.0f,1.0f,0.0f);
				glutWireCone(0.4,0.4,10,10);
			glPopMatrix();
			glEnable(GL_LIGHTING);
		}
		*/
	}
	void Lightning::toggleDebugMode() {
		_isDebug = !_isDebug;
	}
}